var AddTask = {};
AddTask.contextpath = "";
AddTask.initPage = function(contextpath) {
	AddTask.contextpath = contextpath;

	layui
			.use(
					[ 'form', 'layedit', 'laydate' ],
					function() {
						var form = layui.form, layer = layui.layer, layedit = layui.layedit, laydate = layui.laydate;

						// 日期
						laydate.render({
							elem : '#date'
						});
						laydate.render({
							elem : '#date1'
						});

						// 创建一个编辑器
						var editIndex = layedit.build('LAY_demo_editor');

						// 自定义验证规则
						form.verify({
							taskName : function(value) {
								if (value.length == 0) {
									return '请输入任务名称';
								}
							}
							,
							time : function(value) {
								if (value.length == 0) {
									return '请输入时间';
								}
							}
						});
						// 监听提交
						form.on('submit(submit)', function(data) {
							AddTask.ajaxSaveTask(data);
							return false;
						});

					});
}

AddTask.ajaxSaveTask = function(data1) {
	Common.callClient("/web2019/project/ajaxAddTask.action",data1.field,function(data){
		if (data.code == "0000") {
			layer.alert(data.message, { icon: 1, closeBtn: 0 }, function (index) { 
				layer.close(index);
				window.location.href="/"+AddTask.contextpath+"/project/addTask.action";
			});
		} else {
			layer.alert(data.message);
		}
	});
}
